describe("防疫-地图设置", () => {
  beforeEach(() => {
    const username = "admin";
    const password = "123456";
    cy.login(username, password);
    cy.visit("/disinfect/map-setting");
  });

  it.only("tools-选择地图", () => {
    cy.intercept("GET", "/api/robot-disinfect-map/v1/list").as("getMaptList");

    cy.getByData("tools-item").contains("地图").click();

    cy.wait("@getMaptList");

    cy.intercept("GET", "api/robot-disinfect-route/v1/list*").as("getPathList");

    cy.getByData("map-item").first().click();

    cy.wait("@getPathList");

    cy.getByData("path-item").then(($item) => {
      expect($item.length).to.greaterThan(0);
    });
  });

  it("路径列表", () => {
    cy.intercept("GET", "/api/robot-disinfect-route/v1/list*").as(
      "getPathList"
    );

    selectMap();

    cy.contains("路径列表").click();

    cy.wait("@getPathList");

    cy.getByData("path-item").then(($item) => {
      expect($item.length).to.be.greaterThan(0);
    });
  });
  it("充电点列表", () => {
    cy.intercept("GET", "/api/robot-disinfect-charge-point/v1/list*").as(
      "getChargePointList"
    );

    selectMap();

    cy.contains("充电点列表").click();

    cy.wait("@getChargePointList");

    cy.getByData("charge-point-item").then(($item) => {
      expect($item.length).to.be.greaterThan(0);
    });
  });

  it("绘制路径", () => {
    selectMap();
    cy.wait("@getPathList");
    cy.get("canvas").rightclick();
    // cy.get("canvas").trigger("contextmenu");
    cy.get("#contextMenu").should("be.visible");
    cy.contains("绘制路径").click();
    cy.get("canvas").click(400, 500);
    cy.get("canvas").click(420, 520);
    cy.contains("结束绘制").click();
    cy.contains("请输入路径名称")
      .closest(".el-message-box__container")
      .siblings()
      .type("路径999");
    cy.contains("确定").click();
    cy.contains("操作成功");
  });

  it.only("删除路径", () => {
    selectMap();

    cy.wait("@getPathList");

    cy.getByData("path-item").then(($item) => {
      expect($item.length).to.greaterThan(0);
    });

    cy.getByData("path-item").first().click();

    cy.intercept("DELETE", "/api/robot-disinfect-route/v1/*").as("deletePath");

    cy.getByData("path-item").contains("删除").click();

    cy.contains("确认继续操作吗")
      .closest(".el-message-box")
      .contains("确定")
      .click();

    cy.wait("@deletePath");

    cy.contains("操作成功");

    cy.wait("@getPathList");
  });
});

function selectMap() {
  cy.intercept("GET", "/api/robot-disinfect-map/v1/list").as("getMaptList");
  cy.contains("选择地图").click();
  cy.wait("@getMaptList");
  cy.getByData("map-item").then(($item) => {
    expect($item.length).to.greaterThan(0);
  });
  cy.intercept("GET", "api/robot-disinfect-route/v1/list*").as("getPathList");
  cy.getByData("map-item").first().click();
}
